<?php
App::import('Vendor','xtcpdf'); 
$tcpdf = new XTCPDF();
$textfont = 'helvetica'; // looks better, finer, and more condensed than 'dejavusans'
$tcpdf->setHeaderFont(array($textfont,'',40));

$tcpdf->SetAuthor("Ventura Rueda, Jose");
$tcpdf->SetAutoPageBreak(false);
$tcpdf->xheadercolor = array(150,0,0);
$tcpdf->xheadertext = 'Mi Empresa - Desarrollo ha medida';
$tcpdf->xheaderurl = 'http://mi_empresa.pe';
$tcpdf->xfootertext = 'Copyright Â© %d KBS Homes & Properties. All rights reserved.';

// add a page (required with recent versions of tcpdf)
$tcpdf->AddPage();


// cabeceras
$tcpdf->ln(8);
$tcpdf->SetFillColor(249, 249, 249);
$tcpdf->SetFont('helvetica', 'I', 10);
$tcpdf->MultiCell(120, 1, __('Referente a', TRUE), 'B', 'L', 1, 0, '', '', true);
$tcpdf->MultiCell(10, 1, ' ', 0, 'L', 0, 0, '', '', true);
$tcpdf->MultiCell(60, 1, __('Periodo - Fechas', TRUE), 'B', 'L', 1, 1, '', '', true);


$tcpdf->SetFont('helvetica', 'B', 7);
$tcpdf->MultiCell(20, 5,  __('Articulo', TRUE)."\n".__('Almacen', TRUE), 0, 'L', 0, 0, '', '', true);
$tcpdf->MultiCell(4, 5, ':'."\n".':', 0, 'C', 0, 0, '', '', true);
$tcpdf->SetFont('helvetica', '', 7);
$tcpdf->MultiCell(96, 5, $data['Articulo']['descripcion']."\n".$data['Articulo']['almacen'], 0, 'L', 0, 0, '', '', true);
$tcpdf->MultiCell(10, 1, ' ', 0, 'L', 0, 0, '', '', true);
$tcpdf->SetFont('helvetica', 'B', 7);
$tcpdf->MultiCell(20, 5,  __('Fecha inicial', TRUE)."\n".__('Fecha final', TRUE), 0, 'L', 0, 0, '', '', true);
$tcpdf->MultiCell(4, 5, ':'."\n".':', 0, 'C', 0, 0, '', '', true);
$tcpdf->SetFont('helvetica', '', 7);
$tcpdf->MultiCell(36, 5, $data['Articulo']['fecha_de']."\n".$data['Articulo']['fecha_a'], 0, 'L', 0, 0, '', '', true);


$tableHeader = array(__('Numero', TRUE) , __('Nro. Documento', TRUE), __('Tipo Documento', TRUE), __('Fecha', TRUE),
					 __('Ingreso', TRUE), __('Salida', TRUE),__('Stock',TRUE));
$tableHeaderW = array(20,30,60,20,20,20,20);//190
$tcpdf->mostrarHeaderTable($tableHeader,$tableHeaderW,15);	
$numeroLineasPagina = 51;
$numeroLineas = 0;
foreach($kardexes as $key=>$kardex){
	$numeroLineas += 1;
	$nro = $key+1;
	
	if($numeroLineas == $numeroLineasPagina){
		$tcpdf->AddPage();
		$tcpdf->mostrarHeaderTable($tableHeader,$tableHeaderW);
		$numeroLineas = 0;
	}
	
	$stock = empty($this->data['Articulo']['almacen_id'])?$kardex['Documento']['articulo_stock']:$kardex['Documento']['almacen_stock'];
	$tcpdf->Cell($tableHeaderW[0], 4, $nro, 1, 0, 'R', 1);
	$tcpdf->Cell($tableHeaderW[1], 4, $kardex['Documento']['numero'], 1, 0, 'C', 1);
	$tcpdf->Cell($tableHeaderW[2], 4, $kardex['Documento']['descripcion'], 1, 0, 'L', 1);
	$tcpdf->Cell($tableHeaderW[3], 4, $kardex['Documento']['fecha'], 1, 0, 'C', 1);
	$tcpdf->Cell($tableHeaderW[4], 4, $kardex['Documento']['ingreso'], 1, 0, 'R', 1);
	$tcpdf->Cell($tableHeaderW[5], 4, $kardex['Documento']['salida'], 1, 0, 'R', 1);
	$tcpdf->Cell($tableHeaderW[6], 4, $stock, 1, 0, 'R', 1); 
	$tcpdf->Ln();		
}
echo $tcpdf->Output('filename.pdf', 'I');
?>